{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ly商城</title>
    <link href="{% static 'layui/css/layui.css' %}" rel="stylesheet" media="all">
    {% block css %}{% endblock %}
</head>
<body>
<div style="width: 100%;margin: 0 auto">
    <!-- 导航栏 -->
    <div class="layui-row"
         style="width: 90%;margin: 0 auto;border: none;border-bottom: 1px solid #00000036;padding: 10px 30px;">
        <div class="layui-col-xs2" style="text-align: center">
            <h1>ly商城</h1>
        </div>
        <div class="layui-col-xs3" style="display: flex;justify-content: center;color: #2f363c94;">
            <h2 style="margin: 0 10px;"><a href="{% url 'content:首页' %}">首页</a></h2>
            <h2 style="margin: 0 10px;"><a href="{% url 'content:商品列表' %}?name=">商城</a></h2>
            <h2 style="margin: 0 10px;">关于我们</h2>
            <h2 style="margin: 0 10px;">联系我们</h2>
        </div>
        <div class="layui-col-xs3">
            <form class="layui-form" method="get" novalidate action="{% url 'content:商品列表' %}">
                <div class="layui-form-item" style="display: flex">
                    {{ search_form.name }}
                    <button lay-submit type="submit" class="layui-btn  layui-icon layui-icon-search" id="search_button">搜索</button>
                </div>
            </form>
        </div>
        <div class="layui-col-xs4" style="display: flex;justify-content: flex-end">
            <button class="layui-btn layui-btn-primary"><a href="{% url 'login:登录' %}">登录</a></button>
            <button class="layui-btn layui-btn-primary"><a href="{% url 'login:注册' %}">注册</a></button>
            <button class="layui-btn layui-btn-primary"><a href="{% url 'login:退出' %}">退出</a></button>
            <button class="layui-btn layui-btn-primary"><a href="{% url 'login:个人中心' %}">个人中心</a></button>
{#            <button class="layui-btn layui-btn-primary"><a href="{% url 'manager:我的' %}">后台管理</a></button>#}
        </div>
    </div>

    {% block content %}{% endblock %}


    <!--搜索框隐藏的排行榜-->
    <div id="search_top5" style="display: none;text-align: left;margin: 10px;">
        <h1>评分排行榜</h1>

        {% for i in top_5 %}
            <a href="{% url 'content:商品详情'%}?id={{ i.id }}" style="text-decoration: none; color: inherit;">
                <div style="background-color: #F3F4F6; margin: 10px; display: flex; align-items: flex-end; padding: 10px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border: 1px solid #000000;">
                    <img src="{{ i.images.url }}" width="50px" height="50px" style="margin: 10px;">
                    <div style="margin: 10px; display: flex; flex-direction: column; align-items: flex-start;">
                        <div style="font-size: 14px; font-weight: bold;">{{ i.name }}</div>
                        <div style="font-size: 14px; color: gray;">{{ i.rating }}</div>
                    </div>
                </div>
            </a>

        {% endfor %}
    </div>


</div>


<script src="{% static 'layui/layui.js' %}"></script>
<script>
    layui.use(function () {
        var search_input = document.querySelector('#id_name')

        //获取焦点,跳出弹窗,从当前位置开始,往下推动
        search_input.onfocus = function () {
            console.log('获取焦点')
            var html_content = document.querySelector('#search_top5').innerHTML;

            layer.open({
                id: 'search_layer', //防止重复弹出
                type: 1,
                area: ['338px', '500px'], // 宽高
                title: false, // 不显示标题栏
                offset: ['50px', '720px'], // 弹窗位置
                anim: 5,
                closeBtn: 0,
                shade: 0, // 不显示遮罩
                content: html_content,
            });

        }
        //失去焦点,关闭弹窗
        search_input.onblur = function () {
            layer.close('search_layer');
        }
    })


</script>
{% block js %}{% endblock %}

</body>
</html>